package com.holy.sh.couviewholy.bser;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;

/**
 * Holy Email :victorhhl@163.com
 * Create by Holy on 2019/8/9
 * Description :
 */
public class NormalGestureTrackView extends View {
    private Paint mPaint;
    private Path path;
    public NormalGestureTrackView(Context context) {
        super(context);
        initOP();
    }


    public NormalGestureTrackView(Context context, AttributeSet attrs) {
        super(context, attrs);
        initOP();
    }

    public NormalGestureTrackView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initOP();
    }

    private void initOP() {
        path = new Path();
         mPaint = new Paint();
                mPaint.setColor(Color.BLACK);
                mPaint.setStyle(Paint.Style.STROKE);
                mPaint.setStrokeWidth(2);
                mPaint.setAntiAlias(true);
               // mPaint.setStrokeMiter(90);//设置画笔倾斜度
                //mPaint.setPathEffect();//设置路径样式 CopmosePathEffect-》》合并路径类型用的
                // CornerPathEffect，DashPathEffect，DiscreteOathEffect，pathDashPathEffect,SumpathEffect
                //mPaint.setStrokeCap(); Cap.ROUND`SQUARE`BUTT
                //mPaint.setStrokeJoin(Paint.Join.BEVEL); //设置路径转角样式 MITER·ROUND·BEVEL
                //mPaint.setDither(true);//抗抖动，颜色丰富无法显示，过度显示马赛克相邻像素中间插入过渡值

                //Paint 字体相关
                //mPaint.setTextSize();
                mPaint.setFakeBoldText(false);//加粗
                mPaint.setStrikeThruText(false);//删除线
                mPaint.setUnderlineText(false);//下划线
                //mPaint.setTextAlign(false);//开始绘图点位置？
                //mPaint.setTextScaleX();//设置水平拉伸
                //mPaint.setTextSkewX();//设置水平斜度
                //mPaint.setTypeface();设置字体样式




    }

    private float px,py;
    @Override
    public boolean onTouchEvent(MotionEvent event) {
        switch (event.getAction()) {
          /*  case MotionEvent.ACTION_DOWN:
                path.moveTo(event.getX(),event.getY());
                return true;
            case MotionEvent.ACTION_MOVE:
                path.lineTo(event.getX(), event.getY());
                postInvalidate();
                break;

                default:
                    break;*/
            case MotionEvent.ACTION_DOWN:
                path.moveTo(event.getX(),event.getY());
                px = event.getX();
                py = event.getY();
                return true;
            case MotionEvent.ACTION_MOVE:
                float midX=(px+event.getX())/2;
                float midY = (py + event.getY())/2;
                path.quadTo(px,py,midX,midY);
                px=event.getX();
                py=event.getY();
                invalidate();
                break;

            default:
                break;

        }

        return super.onTouchEvent(event);

    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        canvas.drawColor(Color.WHITE);
        canvas.drawPath(path,mPaint);
    }
}
